Excelで1つの列の「 - 」で区切られたデータを複数に分割する (Divide data separated from ' - ' in one column into more in excel)


問題の説明

Excelで1つの列の「 ‑ 」で区切られたデータを複数に分割する (Divide data separated from ' ‑ ' in one column into more in excel)

Microsoft Excel を使用していますが、1 つの列に (スペース、ダッシュ、スペース) で区切られた 2 つの単語が含まれているファイルが与えられました。つまり、次のようなものがあります:

XXXXXX ‑ XXXXXXXXXXXX
XXX ‑ XXXXXXXX
XXXX ‑ XXX

これらの単語を 2 つの異なる列に分けたいと思います。どうやってやるの?よろしくお願いします。


リファレンスソリューション

方法 1:

You tagged the question with VBA but you've not posted any code.

A non VBA solution would be using TEXT TO COLUMNS. Just mark as delimiters the space and the other option (set it to ) and it will work properly:

enter image description here

When using TEXT TO COLUMNS, in step 1 choose Delimited. In step 2, do like this:

enter image description here

Third step, choose Finish

And you will get this:

enter image description here

方法 2:

You will need to loop the cells, using Split to separate the data using "‑" as the separator, and then write these to the appropriate cell.

Sub sSplitHyphen()
    Dim lngRow As Long
    Dim lngLast As Long
    Dim aData() As String
    lngLast = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
    For lngRow = 1 To lngLast
        If InStr(ActiveSheet.Cells(lngRow, 1), "‑") > 0 Then
            aData = Split(ActiveSheet.Cells(lngRow, 1), "‑")
            ActiveSheet.Cells(lngRow, 2) = Trim(aData(0))
            ActiveSheet.Cells(lngRow, 3) = Trim(aData(1))
        End If
    Next lngRow
End Sub

I've used Trim() to remove the leading/trailing spaces. If all of your data is separated by " ‑ " then you could use this to split the data.

Regards,

(by Maurizio SerraFoxfire And Burns And BurnsApplecore)

リファレンスドキュメント

  1. Divide data separated from ' ‑ ' in one column into more in excel (CC BY‑SA 2.5/3.0/4.0)

#vba #excel






関連する質問

2010カスタムリボンにアクセス (access 2010 custom ribbon)

セルに値が保存されているファイルを開く (Open files with values stored in cells)

コンソールはプログラミング言語で制御できますか? (Can consoles be controlled by programming languages?)

このコードを変更して、最後の行の下の行にデータを貼り付けるにはどうすればよいですか? (How do I modify this code to paste in the row under last row with data?)

Selenium-vba クラス名で要素を取得 (Selenium-vba Get element by Class Name)

セルからデータを抽出し、セルをアルファベット順に並べ替えるにはどうすればよいですか? (How do I extract data from a cell and order the cells alphabetically?)

VBAコードがセルをアクティブにしない (VBA code not activating cell)

列をExcel VBAループして、空白以外をコピーして他の3つの列に貼り付けますか? (Excel VBA Loop through Column to Copy and Paste Non Blanks to 3 other Columns?)

コードは 2 つの製品で動作しますが、3 番目の製品コードを追加すると、データが取得されますが、3 番目の製品だけに保存されません。どうしたの? (Code works with two products but when I add a third product code grabs data but doesn't save it only for third product. What's wrong with it?)

シート 2 の範囲内のセル名に基づいてシート (シート 1) を複製して名前を変更するために必要な VBA コード (VBA code needed to duplicate and rename a sheet (Sheet 1) based on cell names in a range on Sheet 2)

signtool.exe エラー: Excel マクロの署名時に SignerSign() が失敗しました (-2147220492/0x800403f4) (signtool.exe Error: SignerSign() failed (-2147220492/0x800403f4) when signing Excel Macro)

Excelで1つの列の「 - 」で区切られたデータを複数に分割する (Divide data separated from ' - ' in one column into more in excel)







コメント